package netapp.tcp_2;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), 6666);
        // 一、客户端向服务器写出数据
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bw.write("お前も死んでいる");
        bw.flush();
        // 在socket中提供方法禁用套接字
        // 只关闭通过Socket对象获取的流，而不影响Socket的使用，如果想要获取，只能从新创建Socket对象
        socket.shutdownOutput();

        // 四、读取服务器的反馈数据
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s = br.readLine();
        System.out.println(s);
        // 关闭客户端
        socket.close();

    }
}
